<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8"/>
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
		<meta name="HandheldFriendly" content="true"/>
		<meta name="MobileOptimized" content="320"/>
		<title>Hello H5+</title>
		<script src="../../js/mui.min.js"></script>
		<link href="../../css/mui.min.css" rel="stylesheet"/>
        <link href="../../css/global.css" rel="stylesheet"/>
		<script type="text/javascript" src="./common.js"></script>
		<script type="text/javascript">
var shares=null,bhref=false;
var Intent=null,File=null,Uri=null,main=null;
// H5 plus事件处理
function plusReady(){
	updateSerivces();
	if(plus.os.name=="Android"){
		Intent = plus.android.importClass("android.content.Intent");
		File = plus.android.importClass("java.io.File");
		Uri = plus.android.importClass("android.net.Uri");
		main = plus.android.runtimeMainActivity();
	}
}
if(window.plus){
	plusReady();
}else{
	document.addEventListener("plusready",plusReady,false);
}
/**
 * 更新分享服务
 */
function updateSerivces(){
	plus.share.getServices( function(s){
		shares={};
		for(var i in s){
			var t=s[i];
			shares[t.id]=t;
		}
	}, function(e){
		outSet( "获取分享服务列表失败："+e.message );
	} );
}

/**
   * 分享操作
   * @param {String} id
   */
function shareAction(id,ex) {
	var s=null;
	outSet( "分享操作：" );
	if(!id||!(s=shares[id])){
		outLine( "无效的分享服务！" );
		return;
	}
	if ( s.authenticated ) {
		outLine( "---已授权---" );
		shareMessage(s,ex);
	} else {
		outLine( "---未授权---" );
		s.authorize( function(){
				shareMessage(s,ex);
			},function(e){
			outLine( "认证授权失败："+e.code+" - "+e.message );
		});
	}
}
/**
   * 发送分享消息
   * @param {plus.share.ShareService} s
   */
function shareMessage(s,ex){
	var msg={content:"",extra:{scene:ex}};
	if(bhref){
		msg.href=sharehref.value;
		if(sharehrefTitle&&sharehrefTitle.value!=""){
			msg.title=sharehrefTitle.value;
		}
		if(sharehrefDes&&sharehrefDes.value!=""){
			msg.content=sharehrefDes.value;
		}
		msg.thumbs=["_www/logo.png"];
		msg.pictures=["_www/logo.png"];
	}else{
		if(pic&&pic.realUrl){
			msg.pictures=[pic.realUrl];
		}
	}
	outLine(JSON.stringify(msg));
	s.send( msg, function(){
		outLine( "分享到\""+s.description+"\"成功！ " );
	}, function(e){
		outLine( "分享到\""+s.description+"\"失败: "+e.code+" - "+e.message );
	} );
}

// 打开分享
function shareShow(){
	bhref=false;
	var ids=[{id:"weixin",ex:"WXSceneSession"},{id:"weixin",ex:"WXSceneTimeline"},{id:"sinaweibo"},{id:"tencentweibo"}],
	bts=[{title:"发送给微信好友"},{title:"分享到微信朋友圈"},{title:"分享到新浪微博"},{title:"分享到腾讯微博"}];
	if(plus.os.name=="iOS"){
		ids.push({id:"qq"});
		bts.push({title:"分享到QQ"});
	}
	plus.nativeUI.actionSheet({cancel:"取消",buttons:bts},
		function(e){
			var i=e.index;
			if(i>0){
				shareAction(ids[i-1].id,ids[i-1].ex);
			}
		}
	);
}
// 分析链接
function shareHref(){
	bhref=true;
	var ids=[{id:"weixin",ex:"WXSceneSession"},{id:"weixin",ex:"WXSceneTimeline"},{id:"qq"}],
	bts=[{title:"发送给微信好友"},{title:"分享到微信朋友圈"}];
	plus.nativeUI.actionSheet({cancel:"取消",buttons:bts},
		function(e){
			var i=e.index;
			if(i>0){
				shareAction(ids[i-1].id,ids[i-1].ex);
			}
		}
	);
}
		</script>
		<link rel="stylesheet" href="./common.css" type="text/css" charset="utf-8"/>
		<style type="text/css">

.sharehref{
	width:80%;
	-webkit-user-select:text;
	border: 1px solid #6C6C6C;
	-webkit-border-radius: 2px;
	border-radius: 2px;
	margin-bottom: .5em;
}
		</style>
	</head>
	<body style="background-color: #f3f3f3;">
		<header class="mui-bar mui-bar-nav title-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left mui-back-new"></a>
			<a onclick="shareHref();" class="mui-pull-right" style="color: #2c2c2c;font-size: 15px;">分享</a>
			<h1 id="title" class="mui-title mhd-title">邀请好友 </h1> 
		</header>
		<div id="dcontent" class="dcontent">
			<div style="display: none;">
			<div style="padding: 0.5em 1em;"><hr color="#EEE"/></div>
			<p class="heading">链接地址：</p>
			<input id="sharehref" class="sharehref" type="url" value="http://120.55.172.215:8081/downloanAPP.html" placeholder="请输入要分享的链接地址"/>
			<p class="heading">链接标题：</p>
			<input id="sharehrefTitle" class="sharehref" type="text" value="邀请好友下载APP并注册可领红包" placeholder="邀请好友下载APP并注册可领红包"/>
			<p class="heading">链接描述：</p>
			<div id="output"></div>
			<input id="sharehrefDes" class="sharehref" type="text" value="我正在使用来理财进行投资理财，赶紧跟我一起来体验！" placeholder="我正在使用来理财进行投资理财"/>
			</div>
			<img style="width: 100%;" src="../../images/logo/invest.jpg" />
			<button class="button" onclick="shareHref()">立即邀请好友</button> 
		</div>
        <div class="title">分享流程</div>
        <div class="prompt">
				1、点击上方 “立即邀请好友” 或右上方 “分享” 按钮。<br/>
				2、在弹出菜单中点击 “发送给微信好友” 或 “分享到微信朋友圈” 。<br/>
				3、选择需要发送的微信好友，或直接 “分享到微信朋友圈” 。<br/>
				4、点击 “分享” 按钮，即可分享成功。<br/> 
		</div>
		<div style="padding-top: 20px;"></div>
		<ul  class="mui-table-view">		
			<li  class="mui-table-view-cell">
				<a onclick="openWindow();" id="invitelink" href="javascript:void(0)" style="padding-left: 20px;color: #2c2c2c;" class="mui-navigate-right">邀请记录
				<span id="tranPwd" class="record_right"></span>
				</a>
			</li>
		</ul>
<script type="text/javascript" src="../../js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/cmw_core.js"></script>
<script type="text/javascript" src="../../js/constant.js"></script>
<script type="text/javascript" src="../../js/global.js"></script>
<script type="text/javascript" src="../../js/form.js"></script>
	</body>
</html>